package com.wechat.server.mp.controller;


import com.wechat.server.mp.common.dto.Vote;
import com.wechat.server.mp.common.exception.HasVoteException;
import com.wechat.server.mp.common.exception.VoteException;
import com.wechat.server.mp.service.VoteService;
import com.wechat.server.mp.util.R;
import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import me.chanjar.weixin.common.error.WxErrorException;
import org.apache.tomcat.util.http.ResponseUtil;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RestController;

import javax.validation.Valid;

/**
 *
 * @author andy
 * @date 2016/12/29
 */
@RequestMapping("vote")
@RestController
@RequiredArgsConstructor
@Slf4j
public class VoteController {
    private final VoteService voteService;

    /**
     * 保存投票者信息
     *
     * @param vote
     * @return
     */
    @RequestMapping(method = RequestMethod.POST)
    public R vote(@RequestBody @Valid Vote vote) throws WxErrorException, HasVoteException, VoteException {

            voteService.save(vote);
            return R.ok();

    }
}
